import Vue from 'vue'
import Router from 'vue-router'
import showLoading from '../components/TopLoading'

Vue.use(Router)

const loadPage = (component) => {
  showLoading.beforeEnter()

  return component.then(r => {
    showLoading.afterEnter()
    return r
  })
}

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Layout',
      component: () => loadPage(import('@/view/Layout/Layout')),
      redirect: '/martin/button',
      children: [
        {
          path: '/martin/dialog',
          name: 'martinDialog',
          oDepth: 2,
          component: () => loadPage(import('@/view/Dialog/Dialog'))
        },
        {
          path: '/martin/button',
          name: 'martinButton',
          oDepth: 3,
          component: () => loadPage(import('@/view/Button/Button'))
        },
        {
          path: '/martin/canvas',
          name: 'martinCanvas',
          oDepth: 7,
          component: () => loadPage(import('@/view/Canvas/Canvas.vue'))
        },
        {
          path: '/martin/font',
          name: 'martinFont',
          oDepth: 4,
          component: () => loadPage(import('@/view/Font/Font'))
        },
        {
          path: '/martin/toast',
          name: 'martinToast',
          oDepth: 5,
          component: () => loadPage(import('@/view/Toast/Toast'))
        },
        {
          path: '/martin/login',
          name: 'martinLogin',
          oDepth: 1,
          component: () => loadPage(import('@/view/Login/Login'))
        },
        {
          path: '/martin/input',
          name: 'martinInput',
          oDepth: 6,
          component: () => loadPage(import('@/view/Input/Input'))
        },
        {
          path: '/martin/pagination',
          name: 'martinPagination',
          oDepth: 7,
          component: () => loadPage(import('@/view/Pagination/Pagination'))
        },
        {
          path: '/martin/notification',
          name: 'martinNotification',
          oDepth: 7,
          component: () => loadPage(import('@/view/Notification/Notification'))
        }
      ]
    }
  ]
})

export default router
